package GUI;

import java.util.Collections;
import java.util.LinkedList;
import java.util.Random;

public class Deck {

	private LinkedList<Card> cards;
	private Card[] flop;
	
	public Deck(){
		cards = new LinkedList<Card>();
		for(Card.Suit suit : Card.Suit.values()){
			for(Card.Rank rank : Card.Rank.values()){
				cards.push(new Card(suit, rank));
			}
		}
		flop = null;
	}
	public boolean isEmpty(){
		return cards.isEmpty();
	}
	public Card nextCard(){
		return cards.pop();
	}
	public Card[] flop(){
		if(cards.size() < 3){
			return null;
		}
			flop = new Card[3];
		for(int i=0; i<flop.length; i++){
			flop[i] = cards.pop();
		}
		return flop;
	}
	public void shuffle(){
		Collections.shuffle(cards, new Random(System.currentTimeMillis()));
	}
	public Card[] nextFaceUp(){
		
		if(flop == null){
			return flop();
		}
		else if(flop.length >= 5)
			return flop;
		int len = flop.length+1;
		Card[] faceups = new Card[len];
		System.arraycopy(flop, 0, faceups, 0,len-1);
		Card newFaceUp = cards.pop();
		faceups[len-1] = newFaceUp;
		flop = faceups;
		return flop;
	}
}
